# -*- coding: utf-8 -*-
from django.db import models
from django import template
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

import os.path
images = os.path.join(
  os.path.dirname(__file__), 'images'
)

class Page(models.Model):
    code = models.CharField(max_length=255, verbose_name=_('code'))
    title = models.CharField(max_length=255, blank=True, verbose_name=_('title'))
    description = models.TextField(blank=True, verbose_name=_('description'))
    keywords = models.CharField(max_length=255, blank=True, verbose_name=_('keywords'))
    content = models.TextField(blank=True, verbose_name=_('content'))
    def __unicode__(self):
        return self.code
    class Meta:
        ordering = ['code']
        verbose_name = _(u'page')
        verbose_name_plural = _(u'pages')

# ARTICLES

class Article(models.Model):
    code = models.CharField(max_length=255, verbose_name=_('code'))
    title = models.CharField(max_length=255,verbose_name=_('title'))
    description = models.TextField(blank=True, verbose_name=_('description'))
    keywords = models.CharField(max_length=255, blank=True, verbose_name=_('keywords'))
    content = models.TextField(verbose_name=_('content'))
    file = models.FileField(upload_to='files/articles', blank=True, verbose_name=_('file'))
    author = models.CharField(max_length=255, verbose_name=_('author'))
    publication = models.CharField(max_length=255,blank=True, verbose_name=_('publication'))
    publication_date = models.DateField(blank=True, null=True, verbose_name=_('publication_date'))
    def __unicode__(self):
        return self.code
    class Meta:
        ordering = ['publication_date']
        verbose_name = _(u'article')
        verbose_name_plural = _(u'articles')

# INSTRUMENTS

class Firm(models.Model):
    name = models.CharField(max_length=255,blank=True, verbose_name=_('name'))
    description = models.TextField(blank=True, verbose_name=_('description'))
    def __unicode__(self):
        return self.name
    class Meta:
        ordering = ['name']
        verbose_name = _(u'firm')
        verbose_name_plural = _(u'firms')

class Grp(models.Model):
    title = models.CharField(max_length=255, blank=True, verbose_name=_('title'))
    def __unicode__(self):
        return self.title
    class Meta:
        ordering = ['title']
        verbose_name = _(u'group')
        verbose_name_plural = _(u'groups')

class WorkList(models.Model):
    store = models.CharField(max_length=255, blank=True, verbose_name=_('store'))
    img = models.ImageField(upload_to='images', blank=True, verbose_name=_('image'))
    def __unicode__(self):
        return self.store
    class Meta:
        ordering = ['store']
        verbose_name = _(u'worklist')
        verbose_name_plural = _(u'worklists')

class Instrument(models.Model):
    code = models.CharField(max_length=255, verbose_name=_('code'))
    name = models.CharField(blank=True, max_length=255, verbose_name=_('name'))
    firm = models.ForeignKey(Firm, verbose_name=_('firm'))
    description = models.TextField(blank=True, verbose_name=_('description'))
    keywords = models.CharField(max_length=255, blank=True, verbose_name=_('keywords'))
    content = models.TextField(blank=True, verbose_name=_('content'))
    groups = models.ManyToManyField(Grp, verbose_name=_('groups'))
    wl = models.ForeignKey(WorkList, verbose_name=_('worklist'))
    img = models.ImageField(upload_to='images', blank=True, verbose_name=_('image'))
    def __unicode__(self):
        return self.code
    class Meta:
        ordering = ['firm', 'name']
        verbose_name = _(u'instrument')
        verbose_name_plural = _(u'instruments')

# TECH

class Tech(models.Model):
    code = models.CharField(max_length=255, verbose_name=_('code'))
    title = models.CharField(max_length=255,verbose_name=_('title'))
    number = models.CharField(max_length=255, verbose_name=_('number'))
    description = models.TextField(blank=True, verbose_name=_('description'))
    keywords = models.CharField(max_length=255, blank=True, verbose_name=_('keywords'))
    content = models.TextField(blank=True, verbose_name=_('content'))
    img = models.ImageField(upload_to='images', blank=True, verbose_name=_('image'))
    def __unicode__(self):
        return self.code
    class Meta:
        ordering = ['number']
        verbose_name = _(u'tech')
        verbose_name_plural = _(u'techs')

# NEWS

class News(models.Model):
    code = models.CharField(max_length=255, verbose_name=_('code'))
    title = models.CharField(max_length=255,verbose_name=_('title'))
    subject = models.CharField(max_length=255,verbose_name=_('subject'))
    description = models.TextField(verbose_name=_('description'))
    keywords = models.CharField(max_length=255, blank=True, verbose_name=_('keywords'))
    content = models.TextField(verbose_name=_('content'))
    publication_date = models.DateField(blank=True, verbose_name=_('publication_date'))
    def __unicode__(self):
        return self.code
    class Meta:
        ordering = ['-publication_date']
        verbose_name = _(u'news')
        verbose_name_plural = _(u'newss')

# Files

class File(models.Model):
    description = models.TextField(blank=True, verbose_name=_('description'))
    file = models.FileField(upload_to='files', blank=True, verbose_name=_('file'))
    def __unicode__(self):
        return self.description
    class Meta:
        ordering = ['file']
        verbose_name = _(u'file')
        verbose_name_plural = _(u'files')

# MENU

class Button(models.Model):
    title = models.CharField(max_length=255, verbose_name=_('name'))
    number = models.CharField(max_length=255, verbose_name=_('number'))
    code = models.ForeignKey(Page, verbose_name=_('page'))
    def __unicode__(self):
        return self.title
    class Meta:
        ordering = ['number']
        verbose_name = _(u'button')
        verbose_name_plural = _(u'buttons')

class MainMenu(models.Model):
    code = models.CharField(max_length=255, verbose_name=_('code'))
    title = models.CharField(max_length=255, verbose_name=_('name'))
    number = models.CharField(max_length=255, verbose_name=_('number'))
    page = models.ForeignKey(Page, verbose_name=_('page'))
    buttons = models.ManyToManyField(Button, blank=True, verbose_name=_('buttons'))
    def __unicode__(self):
        return self.title
    class Meta:
        ordering = ['number']
        verbose_name = _(u'main menu')
        verbose_name_plural = _(u'main menu')

